package com.zjuee.web.warning.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.zjuee.base.bean.response.R;
import com.zjuee.base.constant.Common;
import com.zjuee.base.dto.common.login.LoginDto;
import com.zjuee.base.dto.common.warning.AlarmPromptDto;
import org.springframework.web.bind.annotation.*;
import com.zjuee.service.AlarmPromptService;
import com.zjuee.vo.AlarmPromptVo;

import javax.annotation.Resource;
import javax.validation.constraints.NotNull;

//import org.springframework.security.core.context.SecurityContextHolder;

@RestController
@RequestMapping(path= Common.Service.ZJUEE_CO_WARNING_ALARM_PROMPT_PREFIX)
public class AlarmPromptController {
    @Resource
    AlarmPromptService alarmPromptService;
    @Resource
    LoginDto loginDto;

    @PostMapping("/list_info")
    public R<Page<AlarmPromptVo>> listInfo(AlarmPromptDto alarmPromptDto) {
        try{
            Page<AlarmPromptVo> page=alarmPromptService.listInfo(alarmPromptDto);
            if(null!=page){
                return R.ok(page);
            }
        }catch (Exception e){
            return R.fail(e.getMessage());
        }
        return R.fail();
    }

    @PutMapping("/update")
    public R<Boolean> update(AlarmPromptDto alarmPromptDto) {
        try{
            Boolean update=alarmPromptService.update(alarmPromptDto);
            if(update){
                return R.ok(true);
            }
        }catch (Exception e){
            return R.fail(e.getMessage());
        }
        return R.fail();
    }

    @GetMapping("info/{id}")
    public R<AlarmPromptVo> selectByIdForDetail(@NotNull Long id) {
        try {
            AlarmPromptVo select=alarmPromptService.selectByIdForDetail(id, loginDto.getOrgId());
            if(null!=select){
                return R.ok(select);
            }
        }catch (Exception e){
            return R.fail(e.getMessage());
        }
        return R.fail();
    }
}
